﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WarningAndMonitingSystem.Common;

namespace WarningAndMonitingSystem
{
    public partial class AlarmListForm : Form
    {
        public AlarmListForm()
        {
            InitializeComponent();
        }

        private void AlarmListForm_Load(object sender, EventArgs e)
        {
            dgView.AutoGenerateColumns = false;
            DataContextUtil.UpdateAlarmList += DataContextUtil_UpdateAlarmList;
            UpdateDgView();
        }

        private void DataContextUtil_UpdateAlarmList()
        {
            dgView.Invoke(new Action(() =>
            {
                UpdateDgView();
            }));
        }

        private void UpdateDgView()
        {
            dgView.DataSource = null;
            List<Models.AlarmLogInfo> alarmLogInfos = DataContextUtil.GetAlarmLogInfos();
            if (alarmLogInfos.Count > 0)
            {
                dgView.DataSource = alarmLogInfos;
            }
        }
    }
}
